#!/usr/bin/env bash
#########################################################################
# File Name   : s3.sh
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Tue 2024-11-19 20:59:38(+0800)
#########################################################################

#
#
# Usage:

{
  set -euo pipefail
  APP_ROOT=$(dirname "$(readlink -fm "$0")")
  cd "${APP_ROOT}"

  function logme() {
    local LOGTYPE=$1
    shift
    local MSGC=$*
    local LOGTIME
    LOGTIME="$(date '+%Y-%m-%d %H:%M:%S')"
    case $LOGTYPE in
      i) echo -e "$LOGTIME => INFO  ¦ ${MSGC}" ;;
      d) echo -e "\e[0;96m$LOGTIME => DEBUG ¦ ${MSGC}\e[00m" ;;
      w) echo -e "\e[0;33m$LOGTIME => WARN  ¦ ${MSGC}\e[00m" ;;
      e) echo -e "\e[0;31m$LOGTIME => ERROR ¦ ${MSGC}\e[00m" && return 1 ;;
    esac
  }
}

###
### install nvim
###
mkdir -p ~/.files_saved/
tar xf nvim-linux64.tar.gz -C ~/.files_saved/
mv ~/.files_saved/nvim-linux64 ~/.files_saved/neovim
logme i "install nvim done"

###
### snail-nvim config
###
if [[ -d ~/.config/nvim/ ]]; then
  mv ~/.config/nvim/ ~/.config/nvim-bak-$(date "+%Y%m%d-%H%M%S")
fi
mkdir -p ~/.config/nvim/
rsync -azH ./ ~/.config/nvim/
logme i "snail-nvim config setup done"

###
### tmux
###
ln -s ~/.config/nvim/software/tmux/tmux.conf ~/.tmux.conf
ln -s ~/.config/nvim/software/tmux/tmux_conf ~/.tmux
if ! grep -q 'tmux_profile.sh' ~/.bashrc; then
  echo 'source ~/.config/nvim/software/tmux/tmux_profile.sh' >>~/.bashrc
fi
logme i "tmux setup done"

###
### mason
###
if [[ -d "$HOME"/.local/share/nvim ]]; then
  mv "$HOME"/.local/share/nvim "$HOME"/.local/share/nvim-bak-$(date "+%Y%m%d-%H%M%S")
fi
mkdir -p "$HOME"/.local/share/nvim
ln -s "$HOME"/.config/nvim/mason "$HOME"/.local/share/nvim/mason
logme i "Mason setup!"
